# 设定模块名称
set(TARGET database)

# 在src目录下搜集源码文件
aux_source_directory(src SOURCE_FILES)

# 将模块打包成静态库
add_library(${TARGET}
    STATIC
        ${SOURCE_FILES}
)

# 给模块起个别名，便与其他模块引用(原名的目标依然存在)
add_library(${PROJECT_NAME}::${TARGET} ALIAS ${TARGET})

# 根据构建类型，定义预编译宏
if (CMAKE_BUILD_TYPE STREQUAL Debug)
    # 定义在开发环境下，network_prober.db文件的路径
    set(DB_FILE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/db/network_prober.db")
elseif (CMAKE_BUILD_TYPE STREQUAL Release)
    # 定义在生产环境下，network_prober.db文件的路径
    set(DB_FILE_PATH "/var/lib/${PROJECT_NAME}/network_prober.db")
endif ()

message("数据库文件的路径：DB_FILE_PATH => ${DB_FILE_PATH}")

# 预定义宏：数据库文件路径
target_compile_definitions(${TARGET}
    PRIVATE
        DB_FILE_PATH="${DB_FILE_PATH}"
)

# 将配置文件拷贝到/etc/network_prober目录下
install(
    FILES "${CMAKE_CURRENT_SOURCE_DIR}/db/network_prober.db"
    DESTINATION "/var/lib/${PROJECT_NAME}"
#    PERMISSIONS OWNER_WRITE
    COMPONENT database
)

target_include_directories(${TARGET}
    PUBLIC
        include
)

# 为模块添加依赖
target_link_libraries(${TARGET}
    PRIVATE
        ${PROJECT_NAME}::logger
        ${PROJECT_NAME}::sys_config
        duckdb_static   # 数据库
        Boost::format   # 格式化
        #        gRPC::grpc++    # grpc
        #        #        gRPC::gprc++_reflection
        #        PcapPlusPlus::Pcap++ # 静态库
)

# 给模块增加预编译头文件
target_precompile_headers(${TARGET}
    PRIVATE
        ${PROJECT_INCLUDE_DIR}/pre_compiled.h
)